package day012.neibulei.nimingniebulei;

public class Test {
    public static void main(String[] args) {
        //1.调用方法
        new Swim() {
            @Override
            public void swimming() {
                System.out.println("匿名内部类，重写了接口中的抽象方法...");
            }
        }.swimming();

        //2.作为方法参数传递
        useSwim(new Swim() {
            @Override
            public void swimming() {
                System.out.println("匿名内部类，重写了接口中的抽象方法...");
            }
        });

        //3.作为方法的返回值
        Swim s = getSwim();
        s.swimming();

    }

    public static Swim getSwim() {
        return new Swim() {
            @Override
            public void swimming() {
                System.out.println("匿名内部类，重写了接口中的抽象方法...");
            }
        };
    }

    public static void useSwim(Swim swim) {
        swim.swimming();
    }
}
